﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Crossroad.Utils.Extensions
{
    public static class DecimalExt
    {
        /// <summary>
        /// 是否小于等于0。
        /// </summary>
        /// <returns></returns>
        public static bool IsLessOrEqual0(this decimal value)
        {
            return value <= 0;
        }

        /// <summary>
        /// 是否不等于0。
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsNotEqual0(this decimal value)
        {
            return value != 0;
        }

        /// <summary>
        /// 判断int是NULL或Empty。
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsNullOrEmpty(this decimal? value)
        {
            if (value.IsNull())
                return true;

            return value == 0;
        }

        /// <summary>
        /// 转微信int货币类型(分)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static int ToWechatPrice(this decimal input)
        {
            return Convert.ToInt32(input * 100);
        }

        /// <summary>
        /// 转货币格式字符
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string FormatMoney(this decimal input)
        {
            return $"{input:N2}";
        }
    }
}
